package com.example.administrator.button;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class FuncActivity extends AppCompatActivity {

    private EditText input;
    private TextView re_sin;
    private TextView re_cos;
    private TextView re_tan;
    private TextView re_asin;
    private TextView re_acos;
    private TextView re_atan;
    private Button getRe;

    private Double number = 0.0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_func);
        init();

        getRe.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                number = Double.parseDouble(input.getText().toString());
                re_sin.setText(String.format("SIN:%.4f", Math.sin(number * Math.PI / 180)));
                re_cos.setText(String.format("COS:%.4f", Math.cos(number * Math.PI / 180)));
                re_tan.setText(String.format("TAN:%.4f", Math.tan(number * Math.PI / 180)));
                re_asin.setText(String.format("ASIN:%.4f", Math.toDegrees(Math.asin(number))));
                re_acos.setText(String.format("ACOS:%.4f", Math.toDegrees(Math.acos(number))));
                re_atan.setText(String.format("ATAN:%.4f", Math.toDegrees(Math.atan(number))));
//                Log.v("acos", "acos" + Math.acos(number));
//                Log.v("acosDeg", "acosD" + Math.toDegrees(Math.acos(number)));
            }
        });
    }

    public void init() {
        input = findViewById(R.id.input);
        re_sin = findViewById(R.id.result_sin);
        re_cos = findViewById(R.id.result_cos);
        re_tan = findViewById(R.id.result_tan);
        re_asin = findViewById(R.id.result_asin);
        re_acos = findViewById(R.id.result_acos);
        re_atan = findViewById(R.id.result_atan);
        getRe = findViewById(R.id.getResult);

        number = Double.parseDouble(input.getText().toString());
        re_sin.setText("SIN:" + number.toString());
        re_cos.setText("COS:" + number.toString());
        re_tan.setText("TAN" + number.toString());
        re_asin.setText("ASIN" + number.toString());
        re_acos.setText("ACOS" + number.toString());
        re_atan.setText("ATAN" + number.toString());
    }
}
